<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体育与健康课程管理系统</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/main.css"/>
      <link href="${pageContext.request.contextPath}/public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/public/js/layer/layer.js"></script>
</head>
<style type="text/css" media="screen">
.total{
    width:100%;
    height: 100%;
    background-color: #333;
    position: fixed;
    top:0px;
    opacity:0.5;
    margin:0px;
    z-index: 2;
    display:none;
}    
.add{
    width:400px;
    height:260px;
    background-color: #fff;
    position:fixed;
    top:50px;
    left:30%;
    border-radius: 5px;
z-index: 300;
display: none;
}
.add span
{
    float:right;
    font-size: 30px;
    margin-top: 10px;
    margin-right: 20px;
    color:#666;
    cursor: pointer;
}
.add span:hover
{
    color:#aaa;
}
.add p
{
    font-size: 18px;
    float:left;
    margin-top: 40px;
    margin-left:170px;
    color:#000;
    font-family: '微软雅黑';
    text-align: center;

}
.addtab
{
    float:left;
/*    margin-top:10px;*/
    margin-left: 50px;
}
.addtab tr
{
    float:left;
    margin-top: 20px;
    width:300px;
}
.addtab th
{
    width:90px;
    font-size: 15px;
    font-family: '微软雅黑';
    color:#000;
    float:left;
    font-weight:normal;
}
.addtab input
{
	height:30px;
    border-radius: 5px;
    float:left;
}
.btn12
{
    width:160px;
    height:40px;
    letter-spacing: 10px;
    font-size: 16px;
  
}
.require-red {
    color: #f60;
    font-family: serif;
    margin-right: 3px;
}
</style>
<body>
<div class="total">
</div>
<div class="add" id="add">
<span onclick="ad()">×</span>
<p>添加分类</p>
<form id="myform">
<table  class="addtab">
<tr><th><i class="require-red">*</i>分类名称：</th><td><input  name='problemClassName' type='text'  placeholder="分类名称"></td></tr>
<tr><th><i class="require-red">*</i>分值：</th><td><input  name='problemClassValue' type='text'  placeholder="分值" onkeyup="value=value.replace(/[^\d.]/g,'')">分</td></tr>
</table>
<input class="btn btn-primary btn6 btn12 suba" name="sub" value="添加" type="button" style="margin-left:140px;margin-top:20px">
</form>

</div>
<p style="margin-top:15px;margin-left:40px; font-size:16px; border-left:3px #006dcc solid; padding-left:5px">查看所有分类</p>
<div class="container clearfix" style="width:100%">
    <div class="main-wrap">
        <div class="search-wrap">
        </div>
        <div class="result-wrap" >
               <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:;" onclick="ad()"><i class="icon-font"></i>新增分类</a>
                    </div>
                </div>
                <div class="result-content" id="app" >
                    <table class="result-tab" width="100%" id="addto">
                        <tr>
                            <th width="20%">分类ID</th>
                            <th width="30%">分类名称</th>
                            <th width="30%">分值</th>
                            <th>操作</th>
                        </tr>
                      <c:forEach items="${data}" var="v">
                        <tr >
                            <td>${v.problemClassId}</td>
                            <td><input style="height:30px" type="text" name="problemClassName" value="${v.problemClassName}" onchange="upd(${v.problemClassId},this.value,'problemClassName')" ></td>
                            <td><input style="height:30px" type="text" name="problemClassValue" value="${v.problemClassValue}" onchange="upd(${v.problemClassId},this.value,'problemClassValue')" >分</td>
                            <td>
                            <button type="button" class="btn btn-danger" onclick="dele(${v.problemClassId})">删除</button>
                            </tr>
  					</c:forEach>
                    </table>
                    
                </div>
        </div>
    </div>
</div>

</body>
<script type="text/javascript">
        
        
function ad()
{
    $('.total').toggle(500);
    $('#add').toggle(1000);

}

function dele(id)
{
	$.get("${pageContext.request.contextPath}/problemclass/deleteproblemclass.action",{id:id},function(returndata){
		if(returndata.code==1)
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
	});
}
function upd(id,value,column)
{
	$.post("${pageContext.request.contextPath}/problemclass/updateproblemclass.action",{id:id,value:value,column:column},function(returndata){
		if(returndata.code==1)
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000});  
	});
}


$('.suba').click(function()
    {
    var problemClassName=$('input[name=problemClassName]');
	var problemClassValue=$('input[name=problemClassValue]');
    if(problemClassName.val()=="")
    {
        layer.msg('分类名称不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        problemClassName.focus();
        return ;
    }
    if(problemClassValue.val()=="")
    {
        layer.msg('分值不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        problemClassValue.focus();
        return ;
    }

    var formData=$("#myform").serialize(); 
      $.ajax({
           url: "${pageContext.request.contextPath}/problemclass/addproblemclass.action",//提交地址
           type: 'POST',
           data: formData,
           async: false,
           cache: false,
           processData: false,
           success: function (returndata) {
            if(returndata.code==1){
              layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
            }
            else
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
           },
           error: function (returndata) {
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

       }
      });     

    });
</script>
</html>